<?php

use Phinx\Migration\AbstractMigration;

class User extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('user');
        $table
            ->addColumn('name', 'string',array('limit' => 20))
            ->addColumn('mobile', 'char',array('limit' => 11))
            ->addColumn('email', 'string',array("null"=>true,'limit' => 80))
            ->addColumn('password', 'char',array("null"=>true,'limit' => 32))
            ->addColumn('role_id', 'integer',array("null"=>true))
            ->addColumn('creator', 'integer')
            ->addColumn('status', 'boolean',array('default'=>true))
            ->addColumn('add_time', 'datetime')
            ->create();

        $table->insert(array(
            array(
                "name"=>"Joseph",
                "mobile"=>"1355555555",
                "password"=>md5("111111"),
                "email"=>"1@1.com",
                "creator"=>true,
                "add_time"=>date("Y-m-d H:i:s"),
            )
        ))->save();

    }
}
